package itcast.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import itcast.domain.User;
import itcast.service.UserService;
import itcast.service.UserServiceimpl;

/**
 * Servlet implementation class UserlistServlet
 */
@WebServlet("/userlistServlet")
public class UserlistServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserlistServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	
		//response.getWriter().append("Served at: ").append(request.getContextPath());

		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setCharacterEncoding("UTF-8");//解决输出保存文件乱码问题
		request.setCharacterEncoding("UTF-8");//解决输出保存文件乱码问题
		//1、调用UserService事件层执行查询！
		UserService service=new UserServiceimpl();
		List<User> users =service.findAll();
		//2、将获取到的list存入到request域里面！
		request.setAttribute("users", users);
		//3、转发到allList.jsp里面
		request.getRequestDispatcher("/userList.jsp").forward(request, response);
	}

}
